#include <kernel/vfs.h>
#include <kernel/syslog.h>
#include <kernel/kobject.h>


static LIST_HEAD(fs_list_head);


struct file_system_type* find_fs_by_name(const char *name)
{
	if(!name)
		return NULL;

    struct file_system_type *fs_node;
    struct list_node *head = &fs_list_head;

    list_for_each_entry(fs_node, head, struct file_system_type, link) {
        if(eb_strcmp(fs_node->name, name) == 0) {
            return fs_node;
        }
    }

	return NULL;
}


bool filesystem_register(struct file_system_type *fs)
{
    if(fs == NULL || fs->name == NULL) {
        SYSLOG_ERROR("fs is NULL or name of fs is not set");
        return false;
    }

    if(find_fs_by_name(fs->name)) {
        SYSLOG_ERROR("%s fs is registered", fs->name);
        return false;
    }

    list_add_node_at_tail(&fs_list_head, &fs->link);
}


bool filesystem_unregister(struct file_system_type *fs)
{
    if(fs == NULL || fs->name == NULL) {
        SYSLOG_ERROR("fs is NULL or name of fs is not set");
        return false;
    }

    if(find_fs_by_name(fs->name) == NULL) {
        SYSLOG_ERROR("%s fs is not register", fs->name);
        return false;
    }

    list_del_node(&fs->link);

    return true;
}




void vfs_do_init(void)
{

}
